home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / 3DVIS10.ZIP / SOURCE2.C < prev    next >
Text File  |  1996-02-29  |  2KB  |  78 lines

  1. /*** SOURCE2.C - Creates a .3DV file with the definition of 3 curves
  2.          by Lenimar N. Andrade, ccendm03@brufpb.bitnet
  3.       Dep. of Mathematics - Universidade Federal da Paraíba - Brazil ***/
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <conio.h>
  8.  
  9. unsigned nu = 400;
  10. FILE *arq;
  11.  
  12. /* Parametric equations of the curves */
  13. float f1(float t) { return (5 + 2*sin(5*t))*cos(2*t); }
  14. float f2(float t) { return (5 + 2*sin(5*t))*sin(2*t); }
  15. float f3(float t) { return 2*cos(5*t); }
  16.  
  17. float g1(float t) { return 0.7*(5 + 2*sin(5*t))*cos(2*t); }
  18. float g2(float t) { return 0.7*(5 + 2*sin(5*t))*sin(2*t); }
  19. float g3(float t) { return 0.7*2*cos(5*t); }
  20.  
  21. float h1(float t) { return 1.1*(5 + 2*sin(5*t))*cos(2*t); }
  22. float h2(float t) { return 1.1*(5 + 2*sin(5*t))*sin(2*t); }
  23. float h3(float t) { return 1.1*2*cos(5*t); }
  24.  
  25. /* ------------------------------------------------------------------------- */
  26.  
  27. void CalcPoints2(float umin, float umax) {
  28.  
  29.   float u, incrU;
  30.   unsigned i;
  31.  
  32.   incrU = (umax - umin)/nu;
  33.  
  34.   fprintf(arq, "%u\n", 3*(nu + 1));
  35.   for (u = umin; u < umax + incrU/2; u+= incrU)
  36.     fprintf(arq, "%6.3f %6.3f %6.3f\n", f1(u), f2(u), f3(u));
  37.   for (u = umin; u < umax + incrU/2; u+= incrU)
  38.     fprintf(arq, "%6.3f %6.3f %6.3f\n", g1(u), g2(u), g3(u));
  39.   for (u = umin; u < umax + incrU/2; u+= incrU)
  40.     fprintf(arq, "%6.3f %6.3f %6.3f\n", h1(u), h2(u), h3(u));
  41.  
  42.   fprintf(arq, "%u\n", 4*(nu + 1));
  43.   for (i = 1; i <= nu + 1; i++) {
  44.     fprintf(arq, "%u %u\n", i, 0);
  45.     fprintf(arq, "%u %u\n", nu+ 1 + i, i % 2 == 0 ? BLUE : LIGHTBLUE);
  46.   }
  47.   for (i = 1; i <= nu + 1; i++) {
  48.     fprintf(arq, "%u %u\n", i, 0);
  49.     fprintf(arq, "%u %u\n", 2*(nu+ 1) + i, RED);
  50.   }
  51.  
  52. }
  53.  
  54. /* ------------------------------------------------------------------------- */
  55.  
  56. void PrintMsg(void) {
  57.  
  58.   fprintf(arq, "\n%s", "Segments linking f(t) = ((5+2*sin(5*t))*cos(2*t),"
  59.                "(5+2*sin(5*t))*sin(2*t),"
  60.                "\n                          2*cos(5*t)), 0.7*f(t) and"
  61.                " 1.1*f(t)");
  62.   fprintf(arq, "\n%s", "Lenimar Nunes de Andrade, ccendm03@brufpb.bitnet\n");
  63. }
  64.  
  65. /* ------------------------------------------------------------------------- */
  66.  
  67. void main(void) {
  68.  
  69.   if ((arq = fopen("demo2.3dv", "wt")) == NULL) return;
  70.   CalcPoints2(0, 6.2832);
  71.   PrintMsg();
  72.   fclose(arq);
  73. }
  74.  
  75. /* ------------------------------------------------------------------------- */
  76.  
  77. /*** END OF "SOURCE2.C" ***/
  78.